// pages/search/search.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    searchText: "",
    discoveryPartContent: [],
    discoveryPart: false,
    nationPartcontent: [],
    nationPart: false,
    diquPartContent: [],
    diquPart: false
  },

  showdiscoverydetail:function(e){
    console.log(e)
    var art = e.currentTarget.dataset.art
    wx.navigateTo({
      url: '../discoverydetail/discoverydetail?' + 'art=' + art,
    })
  },

  showdistdetail:function(e){
    console.log(e)
    var database = e.currentTarget.dataset.db
    var city = e.currentTarget.dataset.ct
    wx.navigateTo({
      url: '../destdetail/destdetail?' + 'database=' + database + '&city=' + city,
    })
  },

  blur: function () {
    var that = this
    console.log(this.data.searchText)
    const db = wx.cloud.database()
    if (this.data.searchText != '') {
      //
      db.collection('guoneitop10').where({
        nation: db.RegExp({
          regexp: this.data.searchText,
          options: 'i',
        })
      }).get().then(res => {
        console.log(res.data)
        that.setData({
          diquPartContent: res.data,
        })
        if (res.data.length > 0) {
          that.setData({
            diquPart: true
          })
        } else {
          that.setData({
            diquPart: false
          })
        }
      })

      //
      db.collection('destination').where({
        nation: db.RegExp({
          regexp: this.data.searchText,
          options: 'i',
        })
      }).get().then(res => {
        console.log(res.data)
        that.setData({
          nationPartcontent: res.data,
        })
        if (res.data.length > 0) {
          that.setData({
            nationPart: true
          })
        } else {
          that.setData({
            nationPart: false
          })
        }
      })

      //
      db.collection('postinfo').where({
        title: db.RegExp({
          regexp: this.data.searchText,
          options: 'i',
        })
      }).get().then(res => {
        console.log(res.data)
        that.setData({
          discoveryPartContent: res.data,
        })
        if (res.data.length > 0) {
          that.setData({
            discoveryPart: true
          })
        } else {
          that.setData({
            discoveryPart: false
          })
        }
      })





    } else {
      that.setData({
        diquPart: false,
        nationPart: false,
        discoveryPart: false
      })
    }

  },

  getSearchText: function (e) {
    this.setData({
      searchText: e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})